﻿<%@ Page Language="C#" MasterPageFile="~/Layouts/List.Master" AutoEventWireup="true" CodeBehind="OperationList.aspx.cs" Inherits="Bingosoft.WebApp.Modules.SecurityConsole.Privilege.OperationList" %>

<asp:Content ContentPlaceHolderID="head" ID="idFormTitle" runat="server">
    <!-- title -->
</asp:Content>

<asp:Content ID="idContent" ContentPlaceHolderID="Content" runat="Server">   
    <!-- 搜索框 -->
	<div class="search" style="margin-top:2px;">
        <web:search ID="GridSearch" GridViewId="SmartGridView1" runat="server">            
            <SearchConditionTemplate>                                       
                <table cellpadding="0" cellspacing="0" width="95%">
			        <tr>
                        <th>
                            操作名称：
                        </th>
	                    <td>
		                    <asp:TextBox ID="Name" name="Name" runat="server" ></asp:TextBox>
	                    </td>                
                    </tr>
                </table>
            </SearchConditionTemplate>                      
        </web:search>        
    </div>

    <div class="datalist">
	    <!-- 标题头 -->
	    <h2 style="height:30px;">
				    <%=Request["ParentName"] %>—操作信息列表
	    </h2>
	    <!-- 工具栏 -->
	    <div class="toolbar"  style="height:30px;">
            <asp:LinkButton runat="server"
                OnClientClick="return openEditor(this, 'Insert');" OnClick="SearchGrid">
                <span>
                    <img alt="" runat="server" id="img1" src="~/Images/icon_new.gif" style="border: 0px" />新建操作
                </span>
            </asp:LinkButton>
            <asp:LinkButton runat="server"
                OnClientClick="return delOperations();" OnClick="DelOperations">
                <span>
                    <img alt="" runat="server" src="~/Images/ico_del.gif" style="border: 0px" />删除操作
                </span>
            </asp:LinkButton>
	    </div>
	    <div class="datagrid"  style="clear:left;">    
            <!--------------------------- List Area --------------------------->
            <web:SmartGridView ID="SmartGridView1" runat="server" AutoGenerateColumns="False"
                Width="100%" DataKeyNames="Id" DataSourceID="SmartDataSource1" PageSize="10">
                <Columns>    
                    <asp:CheckBoxField DataField="Id"/>      
                    <asp:BoundField DataField="Code" HeaderText="操作编码" SortExpression="Code" /> 
                    <asp:BoundField DataField="Name" HeaderText="操作名称" SortExpression="Name" />
                    <asp:BoundField DataField="Url" HeaderText="所在页面URL" SortExpression="Url" />
                    <asp:BoundField DataField="ElementId" HeaderText="页面元素ID" SortExpression="ElementId" />
                    <asp:BoundField DataField="ElementBehaviour" HeaderText="页面元素默认行为" SortExpression="ElementBehaviour" />
            
                    <asp:TemplateField HeaderText="操作">
                        <ItemStyle HorizontalAlign="Center" />
                        <HeaderStyle Wrap="False" HorizontalAlign="Center" />
                        <ItemTemplate>
                            <table width="46px">
                                <tr>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="设置规则" _KeyId='<%#Eval("Id")%>' _KeyName='<%#Eval("Name")%>'
                                            ImageUrl="~/images/icon_set_rule.gif" CausesValidation="False" OnClientClick="return setRule(this);" OnClick="RefreshGrid">
                                        </asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ibtnEdit" runat="server" ToolTip="修改" _KeyId='<%#Eval("Id")%>'
                                            ImageUrl="~/images/com/dg_edit.gif" CausesValidation="False" OnClientClick="return openEditor(this, 'Edit');" OnClick="RefreshGrid">
                                        </asp:ImageButton>
                                    </td>
                                    <td style="border: 0px solid #fff;">
                                        <asp:ImageButton ID="ibtnDelete" runat="server" ToolTip="删除" ImageUrl="~/images/com/dg_del.gif" _KeyId='<%#Eval("Id")%>'
                                            CausesValidation="False" OnClientClick="return confirm('您确认要删除吗?')" OnClick="DelOperation">
                                        </asp:ImageButton>
                                    </td>
                                </tr>
                            </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <CheckBoxSettings Enabled="True" Position="0" />
                <PagerSettings />
                <EditRowStyle HorizontalAlign="Center" />
            </web:SmartGridView>
    
            <web:SmartSqlDataSource ID="SmartDataSource1" runat="server" SelectCommand="privilege.operation.list"
            SelectCommandAutoPageWrap="true" DefaultSortExpression="Id DESC">       
            </web:SmartSqlDataSource>
        </div>
	</div>

    <script type="text/javascript">
        var parentId = "<%=Request["ParentId"] %>";
        var parentName = "<%=Request["ParentName"] %>";

        function openEditor(_this, action) {
            var url = "OperationEdit.aspx";

            // FormViewMode : Insert/Edit/ReadOnly
            var params = { FormViewMode: action }
            if (action == "Insert") {
                params.title = "注册操作";
                params.ParentId = parentId;
                params.ParentName = parentName;
            } else if (action == "Edit") {
                params.title = "修改操作";
                params.Id = _this.attributes["_KeyId"].value;
                params.ParentName = parentName;
            }

            var returnValue = showCenterModalDialog(buildUrl(url, params), 600, 400, null);
            if (returnValue == "true") {
                window.parent.reloadTree();
                return true;
            }

            return false;
        }

        function setRule(_this) {
            var url = "OperationRuleList.aspx";

            var params = {};
            params.title = "规则设置";
            params.Operation = _this.attributes["_KeyId"].value;
            params.OperationName = _this.attributes["_KeyName"].value;

            var returnValue = showCenterModalDialog(buildUrl(url, params), 650, 400, null);
            if (returnValue == "true") {
                window.parent.reloadTree();                
                return true;
            }

            return false;
        }

        function delOperations() {
            var oSmartGridView1 = document.getElementById("<%=SmartGridView1.ClientID%>");
            var sValues = oSmartGridView1.control.getCheckedValues(true);

            if (sValues && sValues.length > 0) {
                return confirm('您确认要删除吗?');
            }

            alert("请您选择要删除的操作！");
            return false;
        }        
    </script>
</asp:Content>